from pms.common.views import PostFormula
from project.utils.role import add_project_role, project_role_view
from project.models import Project
from project.utils.permission import assert_project_permissions


class API(PostFormula):
    def handle(self, req):
        pid = req['id']
        assert_project_permissions(pid, self.user.id, [4])
        name = req['name']
        return self.success_respond(project_role_view(
            project_role=add_project_role(
                project=Project.objects.get(id=pid),
                name=name
            )
        ))
